﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Pavilion.NodeDesigner
{
    /// <summary>
    /// Interaction logic for PavilionNodeManager.xaml
    /// </summary>
    public partial class PavilionNodeManager : UserControl
    {
        public PavilionNodeManager()
        {
            InitializeComponent();
        }

        private void Grid_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
        {
            var moveThumb = e.OriginalSource as MoveThumb;
            var listBoxItem = moveThumb.DataContext as ListBoxItem;
            var anchorGrid = listBoxItem.Template.FindName("anchorGrid", listBoxItem) as Grid;

            foreach (UIElement child in anchorGrid.Children)
            {
                var anchor = child as Anchor;
                if (anchor != null)
                    anchor.UpdatePosition();
            }
        }

        private void anchorGrid_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            var grid = sender as Grid;
            (grid.FindName("anchorGrid") as Grid).Visibility = Visibility.Visible;
        }

        private void anchorGrid_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            var grid = sender as Grid;
            (grid.FindName("anchorGrid") as Grid).Visibility = Visibility.Hidden;
        }
    }
}
